package com.neu.wms.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neu.wms.dto.ReceiptInfoDto;
import com.neu.wms.service.WmsReceiptOrderService;
import com.neu.wms.util.ResultVo;
import com.neu.wms.vo.ReceiptVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/wmsreceiptorder")
@Slf4j
public class WmsReceiptOrderController {
    @Autowired
    private WmsReceiptOrderService wmsReceiptOrderService;

    @PostMapping("queryAll")
    public ResultVo queryAll(@RequestBody ReceiptInfoDto receiptInfoDto) {
        PageHelper.startPage(receiptInfoDto.getCurrentPage(), receiptInfoDto.getPageSize(), true);
        List<ReceiptVo> receiptVos = wmsReceiptOrderService.selectAll(receiptInfoDto);
        PageInfo<ReceiptVo> pageInfo = new PageInfo<>(receiptVos);
        return ResultVo.ok().data("list", receiptVos).data("total", pageInfo.getTotal());
    }

    @DeleteMapping("{id}")
    public ResultVo delete(@PathVariable("id") Long id) {
        int i = wmsReceiptOrderService.deleteByPrimaryKey(id);
        if (i > 0) {
            return ResultVo.ok("删除成功");
        } else {
            return ResultVo.error("删除失败");
        }
    }
}
